package com.ly.mpayment.rest.system.yidong;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ly.mpayment.core.util.BigUtil;
import com.ly.mpayment.core.util.JsonUtils;
import com.ly.mpayment.core.util.MapUtil;
import com.ly.mpayment.core.util.ResultMessage;
import com.ly.mpayment.persist.service.user.IUserService;
import com.ly.mpayment.persist.service.yidong.IGameOrderService;
import com.ly.mpayment.persist.service.yidong.IMobileOrdersService;
import com.ly.mpayment.rest.AbsRest;

import cn.jpush.api.utils.StringUtils;
import net.sf.json.JSONObject;
@Component
@Path("system/gameorder")
public class GameRest extends AbsRest {

	@Autowired
	IUserService userService;

	@Autowired
	IMobileOrdersService orderService;

	@Autowired
	IGameOrderService gameService;

	@POST
	@Path("pageGameOrders")
	public String pageGameOrders(String data, @Context HttpServletRequest request){


		String result = this.validationParameter(data,request, userService, "start","pageSize","startTime","endTime",
				"orderId","orderAmount","remark","orderState");
		if(result == null){
			Map<String, Object> parameters = MapUtil.getMap();
			JSONObject json = JsonUtils.converToJson(data);
			if(!StringUtils.isEmpty(json.getString("startTime"))){
				parameters.put(":startTime", json.getString("startTime"));
			}
			if(!StringUtils.isEmpty(json.getString("endTime"))){
				parameters.put(":endTime", json.getString("endTime"));
			}

			if(!StringUtils.isEmpty(json.getString("orderId"))){
				parameters.put(":orderId", json.getString("orderId"));
			}
			if(!StringUtils.isEmpty(json.getString("orderAmount"))){
				parameters.put(":orderAmount", BigUtil.getBigDecimal(json.getString("orderAmount")));
			}
			if(!StringUtils.isEmpty(json.getString("remark"))){
				parameters.put(":remark", json.getString("remark"));
			}
			if(!StringUtils.isEmpty(json.getString("orderState"))){
				parameters.put(":orderState", json.getInt("orderState"));
			}

			return ResultMessage.getSucceed( JsonUtils.excludes(gameService.pageOrders(parameters, json.getInt("start"), json.getInt("pageSize")),
					new String[]{"loginInfos","mobileOrderses"}));
		}
		return result;
	}
}
